home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / HardwareContext-ns32k.h < prev    next >
C/C++ Source or Header  |  1990-07-09  |  3KB  |  110 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. // Copyright (C) 1989 University of Colorado, Boulder, Colorado
  5. // Copyright (C) 1990 University of Colorado, Boulder, Colorado
  6. //
  7. // written by Dirk Grunwald (grunwald@foobar.colorado.edu)
  8. //
  9. #ifndef    HardwareContext_h
  10. #define    HardwareContext_h
  11. #pragma once
  12.  
  13. #include <stream.h>
  14. #include <assert.h>
  15. #include <AwesimeConfig.h>
  16.  
  17. extern const long MagicStackMarker;
  18.  
  19. typedef void (*voidFuncP)();
  20.  
  21. class CpuMultiplexor;
  22. class SingleCpuMux;
  23. class MultiCpuMux;
  24. class SimulationMultiplexor;
  25.  
  26. typedef long HardwareContextQuad;
  27.  
  28. class HardwareContext {
  29.     //
  30.     //    The following four fields are machine dependent & their order
  31.     //    should not be changed.
  32.     //
  33.     HardwareContextQuad sp;
  34.     HardwareContextQuad fp;
  35.  
  36.     void** stackBase;    // bottom of stack
  37.     void** stackEnd;    // maximum depth of stack? (actually, a MIN value)
  38.     unsigned stackMax;    // maximum depth of stack? (actually, a MIN value)
  39.     unsigned stackSize;    // stack size in units of void*
  40.     void **stackMallocAt;
  41.     long *stackCheck;    // point to MagicStackMarker to check for corruption
  42.     unsigned checkStackLimits;
  43.     
  44.     friend class Thread;
  45.     friend class CpuMultiplexor;
  46.     friend class SingleCpuMux;
  47.     friend class MultiCpuMux;
  48.     friend class SimulationMultiplexor;
  49.     
  50.     //
  51.     //    Accessed by friend classes only
  52.     //
  53.     void switchContext(HardwareContext *to);
  54.     void magicSwitchTo(HardwareContext *to);
  55.     void **getSp();
  56.     
  57.     void **mallocAt();
  58.     void buildReturnFrame(void * returnThis, voidFuncP returnAddress);
  59.     void stackOverflow();
  60.     
  61.     //
  62.     // never allocated by anything other than friend classes
  63.     //
  64.     HardwareContext(int checked, unsigned stackSize);
  65.     void reclaimStack();
  66.     
  67. public:
  68.     HardwareContext();
  69.     
  70.     long maxStackDepth();
  71.     void checkStack(int overage = 0);
  72.     void classPrintOn(ostream& strm);
  73. };
  74.  
  75. inline
  76. HardwareContext::HardwareContext()
  77. {
  78.     int NotReached = 0;
  79.     assert( NotReached );
  80. }
  81.  
  82. inline ostream&
  83. operator<<(ostream& strm, HardwareContext& ob)
  84. {
  85.     ob.classPrintOn(strm);
  86.     return strm;
  87. }
  88.  
  89. inline void **
  90. HardwareContext::getSp()
  91. {
  92.     void **foo;
  93.     asm volatile ("sprd sp,%0" : "=g" (foo));
  94.     return( foo );
  95. }
  96.  
  97. inline void
  98. HardwareContext::checkStack(int overage)
  99. {
  100.     unsigned depth = stackBase - getSp() + overage;
  101.     if (stackMax < depth) {
  102.     stackMax = depth;
  103.     }
  104.     if ( stackMax >= stackSize || *stackCheck != MagicStackMarker ) {
  105.     stackOverflow();
  106.     }
  107. }
  108.  
  109. #endif    HardwareContext_h
  110.